/**
 * 
 */
package com.kelaite.procurement.controller;


import static java.lang.String.format;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ch.qos.logback.classic.Logger;

import com.kelaite.procurement.entity.TUser;
import com.kelaite.procurement.exception.BusinessException;
import com.kelaite.procurement.restful.BaseController;
import com.kelaite.procurement.service.PipelineHeaderService;
import com.kelaite.procurement.service.PipelineItemService;
import com.kelaite.procurement.service.UserService;
import com.kelaite.procurement.service.VendorService;

/**
 * @author Allen
 *
 */
@Controller
@RequestMapping("/pipeline")
public class PipelineController extends BaseController{
	
	private static final Logger logger = (Logger) LoggerFactory.getLogger(PipelineController.class);

	@Autowired
	private PipelineHeaderService pipelineHeaderService;
	
	@Autowired
	private PipelineItemService pipelineItemService;
	
	@Autowired
	private VendorService vendorService;
	
	@Autowired
	private UserService userService;
	
	/**
	 * 招标信息
	 * @param request
	 * @param response
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/index", method = {RequestMethod.GET, RequestMethod.POST})
	public String notstarted(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		try {
			//query pipeline
			List<TUser> userList = userService.getByProperty("username", this.getCurrentUsername(session));
			TUser user = userList.get(0);
			if(user.gettCompany() == null){
				throw new BusinessException(format("user[%s] not associated with a company. ", this.getCurrentUsername(session)));
			}
			//List<TPipeline> pipelineList = this.pipelineService.getPipelineBySupplier(user.gettCompany());
			//request.setAttribute("pipelineList", pipelineList);
			return "pipeline/b1_supplier";
		} catch (Exception e) {
			logger.error(e.getMessage());
			return "error";
		}
	}

	@Override
	protected Class<?> getCurrentClass() {
		return this.getClass();
	}
	
}
